package com.gwz.sys.controller;



import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import com.gwz.common.BaseController;
import com.gwz.sys.service.IRoomService;
import com.gwz.sys.utils.DataGridView;
import com.gwz.sys.utils.ResultObj;
import com.gwz.sys.vo.RoomVo;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author gwz
 * @since 2019-01-04
 */
@RestController
@RequestMapping("/room")
public class RoomController extends BaseController {

	@Autowired
	private IRoomService roomService;
	
	@RequestMapping("loadAllRoom")
	public DataGridView loadAllRoom(RoomVo roomVo){
		return roomService.queryAllRoom(roomVo);
	}
	
	@RequestMapping("addRoom")
	public ResultObj addRoom(RoomVo roomVo) {
		ResultObj resultObj = new ResultObj(200, "添加成功");
		try {
			roomService.save(roomVo);
			return resultObj;
		} catch (Exception e) {
			resultObj.setCode(-1);
			resultObj.setMsg("添加失败");
			e.printStackTrace();
			return resultObj;
		}
	}
	
	@RequestMapping("deleteRoom")
	public ResultObj deleteRoom(RoomVo roomVo) {
		ResultObj resultObj = new ResultObj(200, "删除成功");
		try {
			roomService.removeById(roomVo.getId());
			return resultObj;
		} catch (Exception e) {
			resultObj.setCode(-1);
			resultObj.setMsg("删除失败");
			e.printStackTrace();
			return resultObj;
		}
	}
	
}

